package com.zpark.controller;

import com.zpark.pojo.Empty;
import com.zpark.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiaoyu
 * @version 1.0 2022/9/8
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @RequestMapping("/find_all_empty")
    public List<Empty> findAllEmpty() {
        return userService.findAll();
    }

    //@RequestBody 将请求参数以 json 格式接收
    @RequestMapping("/add_empty")
    public String addEmpty(Empty empty) {
        userService.addEmpty(empty);
        return "添加用户成功";
    }

    @RequestMapping("/update_empty")
    public String updateEmpty(Empty empty) {
        userService.changeEmptyById(empty);
        return "修改用户成功";
    }

    @RequestMapping("/del_empty/{id}")
    public String removeEmpty(@PathVariable("id") Integer id) {
        userService.removeEmptyById(id);
        return "删除用户成功";
    }

    @RequestMapping("/find_by_user/{username}")
    public List<Empty> findByUsername(@PathVariable("username") String username) {
        return userService.findByUsername(username);
    }

    @RequestMapping("/find_by_page")
    public List<Empty> findByPage(@RequestParam(value = "pageNum", required = true, defaultValue = "1")
                                              Integer pageNum,
                                  @RequestParam(value = "pageSize", required = true, defaultValue = "1")
                                              Integer pageSize) {
        return userService.findByPage(pageNum, pageSize);
    }

}
